package gui;

import java.awt.Color;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import Game.Core;


import net.miginfocom.swing.MigLayout;

public class StatisticPanel extends JPanel{
	private JButton start;
	private JLabel statsLabels[];
	private static JLabel stats[];//ile mrowek w kazdej grupie
	private MigLayout layout;
	private static GamePanel gPanel;
	
	public StatisticPanel(GamePanel game) {	
		this.gPanel = game;
		this.setSize(100, 500);
		this.setVisible(true);
		init();
	}
	
	private void init(){
		layout = new MigLayout();		
		start = new JButton("Start");
		start.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Core c = new Core();
				//Position[][] b = c.getBATTLEFIELD();
//				for(int i = 0; i<b.length; i++){
//					for(int j = 0; j<b[i].length; j++){
//						System.out.println(b[i][j].getX()+ ", " + b[i][j].getY());
//					}
//				}
				//gPanel.updateAnts(b);
			}
		});
		
		statsLabels = new JLabel[5];
		stats = new JLabel[5];
		statsLabels[0] = new JLabel("��te: ");
		statsLabels[0].setForeground(Color.YELLOW);
		statsLabels[1] = new JLabel("Czerwone: ");
		statsLabels[1].setForeground(Color.RED);
		statsLabels[2] = new JLabel("Zielone: ");
		statsLabels[2].setForeground(Color.GREEN);
		statsLabels[3] = new JLabel("Niebieskie: ");
		statsLabels[3].setForeground(Color.BLUE);
		statsLabels[4] = new JLabel("Liczba epok: ");
		
		stats[0] = new JLabel("0");
		stats[1] = new JLabel("0");
		stats[2] = new JLabel("0");
		stats[3] = new JLabel("0");
		stats[4] = new JLabel("0");
		
		this.setLayout(layout);	
		this.add(statsLabels[0]);
		this.add(stats[0],"wrap");
		this.add(statsLabels[1]);
		this.add(stats[1],"wrap");
		this.add(statsLabels[2]);
		this.add(stats[2],"wrap");
		this.add(statsLabels[3]);
		this.add(stats[3],"wrap");
		this.add(statsLabels[4]);
		this.add(stats[4],"wrap");
		this.add(start,"wrap");
	}
	
	public static void updateGame(){
		gPanel.updateAnts(Core.getBATTLEFIELD());	
		stats[0].setText(Integer.toString(Core.getAmountYellow()));
		stats[1].setText(Integer.toString(Core.getAmountRed()));
		stats[2].setText(Integer.toString(Core.getAmountGreen()));
		stats[3].setText(Integer.toString(Core.getAmountBlack()));
		stats[4].setText(Integer.toString(Core.getGameAge()));			
	}
	
	public static void showWin(String stado){
		JOptionPane.showMessageDialog(null, "Wygra�o stado " + stado + " w " + Core.getGameAge() + " epokach.");
	}
	
//	protected void paintComponent(Graphics g){
//		
//	}
}
